package com.gr.controller;

import com.gr.entity.Tea;
import com.gr.entity.Type;
import com.gr.service.TeaService;
import com.gr.service.TypeService;
import com.gr.service.impl.TeaServiceImpl;
import com.gr.service.impl.TypeServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/type")
public class TypeController {
    TypeService ts=new TypeServiceImpl();
    TeaService teaService=new TeaServiceImpl();
    @RequestMapping("/selectAllType")
    public String selectAll(Model model){
        List<Type> types = ts.selectAll();
        types.forEach(System.out::println);
        model.addAttribute("types",types);
        return "/tealist.jsp";
    }
    @RequestMapping("/selectAllTypeAndTeaNum")
    public String selectAllTypeAndTeaNum(Model model){
        List<Type> types = ts.selectAllTypeAndTeaNum();
        types.forEach(System.out::println);
        model.addAttribute("types",types);
        return "/categorylist.jsp";
    }
    @RequestMapping("/deleteTypeAndTea")
    public String deleteTypeAndTea(Integer id){
        ts.deleteById(id);
        teaService.deleteTeaByBid(id);
        //删除完重定向至查询所有品牌和饮品数量的controller
        return "redirect:/type/selectAllTypeAndTeaNum.do";
    }

}
